home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / comm / term / term_source.lha / Extras / Source / gtlayout-source.lha / LTP_DrawBox.c < prev    next >
C/C++ Source or Header  |  1996-10-03  |  4KB  |  170 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. VOID
  15. LTP_DrawMultiLineButton(struct RastPort *RPort,LONG Left,LONG Top,LONG Width,LONG Height,struct ImageInfo *ImageInfo,BOOL Bold)
  16. {
  17.     LONG Len,ThisTop,ThisLeft;
  18.     STRPTR *Lines = ImageInfo->Lines;
  19.     LONG LineCount = ImageInfo->LineCount;
  20.     STRPTR KeyStroke = ImageInfo->KeyStroke;
  21.     STRPTR Label;
  22.     ULONG OldStyle;
  23.     struct TextFont *OldFont;
  24.  
  25.     if(ImageInfo->Font)
  26.     {
  27.         OldFont = RPort->Font;
  28.  
  29.         SetFont(RPort,ImageInfo->Font);
  30.     }
  31.     else
  32.         OldFont = NULL;
  33.  
  34.     OldStyle = RPort->AlgoStyle;
  35.  
  36.     if(Bold)
  37.         SetSoftStyle(RPort,FSF_BOLD,FSF_BOLD);
  38.  
  39.     if(!LineCount)
  40.         LineCount = 1;
  41.  
  42.     ThisTop = Top + (Height - LineCount * RPort->TxHeight + 1) / 2;
  43.  
  44.     do
  45.     {
  46.         if(LineCount && Lines)
  47.             Label = *Lines++;
  48.         else
  49.             Label = ImageInfo->Label;
  50.  
  51.         Len = strlen(Label);
  52.  
  53.         ThisLeft = Left + (Width - TextLength(RPort,Label,Len)) / 2;
  54.  
  55.         LTP_PrintText(RPort,Label,Len,ThisLeft,ThisTop);
  56.  
  57.         if(KeyStroke)
  58.         {
  59.             if(KeyStroke >= Label && KeyStroke < Label + Len)
  60.             {
  61.                 if(KeyStroke != Label)
  62.                     ThisLeft += TextLength(RPort,Label,(ULONG)KeyStroke - (ULONG)(Label));
  63.  
  64.                 SetSoftStyle(RPort,FSF_UNDERLINED,FSF_UNDERLINED);
  65.  
  66.                 LTP_PrintText(RPort,KeyStroke,1,ThisLeft,ThisTop);
  67.  
  68.                 SetSoftStyle(RPort,0,FSF_UNDERLINED);
  69.  
  70.                 KeyStroke = NULL;
  71.             }
  72.         }
  73.  
  74.         ThisTop += RPort->TxHeight;
  75.     }
  76.     while(--LineCount > 0);
  77.  
  78.     if(Bold)
  79.         SetSoftStyle(RPort,OldStyle,FSF_BOLD);
  80.  
  81.     if(OldFont)
  82.         SetFont(RPort,OldFont);
  83. }
  84.  
  85. VOID
  86. LTP_DrawBox(struct RastPort *rp,struct DrawInfo *drawInfo,LONG left,LONG top,LONG width,LONG height,BOOL selected,BOOL ghosted,ImageInfo *imageInfo)
  87. {
  88.     LONG pen3,pen4;
  89.     LONG imageType;
  90.     LONG Width,Height;
  91.     UWORD *pens;
  92.  
  93.         // It doesn't work reliably under v2.04 without these
  94.  
  95.     if(!V39)
  96.         LTP_ResetRenderInfo(rp);
  97.  
  98.     pens = drawInfo->dri_Pens;
  99.  
  100.     LTP_RenderBevel(rp,pens,left,top,width,height,selected,imageInfo->Emboss ? 3 : 2);
  101.  
  102.     if(selected)
  103.     {
  104.         pen3 = pens[FILLPEN];
  105.         pen4 = pens[FILLTEXTPEN];
  106.     }
  107.     else
  108.     {
  109.         pen3 = pens[BACKGROUNDPEN];
  110.         pen4 = pens[TEXTPEN];
  111.     }
  112.  
  113.     LTP_SetAPen(rp,pen3);
  114.  
  115.     if(imageInfo->Emboss)
  116.     {
  117.         Width    = 3;
  118.         Height    = 2;
  119.     }
  120.     else
  121.     {
  122.         Width    = 2;
  123.         Height    = 1;
  124.     }
  125.  
  126.     LTP_FillBox(rp,left + Width,top + Height,width - 2 * Width,height - 2 * Height);
  127.  
  128.     LTP_SetPens(rp,pen4,0,JAM1);
  129.  
  130.     switch(imageType = imageInfo->ImageType)
  131.     {
  132.         case IMAGECLASS_PICKER:
  133.  
  134.             Width    = 2 + (((width + 15) / 16) * drawInfo->dri_Resolution.Y) / drawInfo->dri_Resolution.X;
  135.             Height    = 1 + ((height + 15) / 16);
  136.  
  137.             if(Width < 4)
  138.                 Width = 4;
  139.  
  140.             LTP_DrawPicker(rp,FALSE,left + Width,top + Height,width - 2 * Width,height - 2 * Height);
  141.             break;
  142.  
  143.         case IMAGECLASS_MULTILINEBUTTON:
  144.  
  145.             LTP_DrawMultiLineButton(rp,left + Width,top + Height,width - 2 * Width,height - 2 * Height,imageInfo,imageInfo->Emboss);
  146.             break;
  147.  
  148.         case IMAGECLASS_LEFTINCREMENTER:
  149.         case IMAGECLASS_RIGHTINCREMENTER:
  150.  
  151.             LTP_DrawIncrementer(rp,drawInfo,imageType == IMAGECLASS_LEFTINCREMENTER,left + 2,top + 1,width - 4,height - 2);
  152.             break;
  153. #ifdef DO_TAPEDECK_KIND
  154.         case IMAGECLASS_BACKWARD:
  155.         case IMAGECLASS_FORWARD:
  156.         case IMAGECLASS_PREVIOUS:
  157.         case IMAGECLASS_NEXT:
  158.         case IMAGECLASS_RECORD:
  159.         case IMAGECLASS_PLAY:
  160.         case IMAGECLASS_STOP:
  161.         case IMAGECLASS_PAUSE:
  162.         case IMAGECLASS_EJECT:
  163.         case IMAGECLASS_REWIND:
  164.  
  165.             LTP_DrawTapeButton(rp,imageInfo,left,top,width,height,drawInfo->dri_Resolution.X,drawInfo->dri_Resolution.Y,pen3);
  166.             break;
  167. #endif    /* DO_TAPEDECK_KIND */
  168.     }
  169. }
  170.